package com.aurora.springbootmybatis.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

public class StringUtil {
    public StringUtil() {
    }

    public static boolean isEmpty(String str) {
        return str == null || "".equals(str.trim());
    }

    public static boolean isNotEmpty(String str) {
        return str != null && !"".equals(str.trim());
    }

    public static String formatLike(String str) {
        return isNotEmpty(str) ? "%" + str + "%" : null;
    }

    public static List<String> filterWhite(List<String> list) {
        List<String> resultList = new ArrayList();
        Iterator var2 = list.iterator();

        while(var2.hasNext()) {
            String l = (String)var2.next();
            if (isNotEmpty(l)) {
                resultList.add(l);
            }
        }

        return resultList;
    }

    public static String stripHtml(String content) {
        content = content.replaceAll("<p .*?>", "\r\n");
        content = content.replaceAll("<br\\s*/?>", "\r\n");
        content = content.replaceAll("\\<.*?>", "");
        content = content.replaceAll(" ", "");
        return content;
    }

    public static String genSixRandomNum() {
        Random random = new Random();
        String result = "";

        for(int i = 0; i < 6; ++i) {
            result = result + random.nextInt(10);
        }

        return result;
    }

    public static String getRandomString(int length) {
        Random random = new Random();
        StringBuffer sb = new StringBuffer();

        for(int i = 0; i < length; ++i) {
            int number = random.nextInt(2);
            long result = 0L;
            switch (number) {
                case 0:
                    result = Math.round(Math.random() * 25.0 + 65.0);
                    sb.append(String.valueOf((char)((int)result)));
                    break;
                case 1:
                    sb.append(String.valueOf((new Random()).nextInt(10)));
            }
        }

        return sb.toString();
    }
}
